package test

import config.MyFile
import org.apache.commons.io.FileUtils

import scala.io.Source
import scala.jdk.CollectionConverters._

object network extends MyFile {

  def main(args: Array[String]): Unit = {
    Source.fromFile("H:\\紫花苜蓿数据库\\2022_12_19\\Cytoscape/CytoscapeInput-edges.txt".toFile).getLines().take(100).foreach(println)
  }

  def xxx = {
    Source.fromFile("H:\\紫花苜蓿数据库\\2022_12_19\\Cytoscape/CytoscapeInput.txt".toFile).getLines().grouped(100000).foreach { x =>
      val lines = x.filter { y =>

        val l = y.split("\t")
        l(2).toDouble >= 0.5
      }
      FileUtils.writeLines("H:\\紫花苜蓿数据库\\2022_12_19\\Cytoscape/CytoscapeInput_filter.txt".toFile, lines.asJava, true)

    }
  }


  def dropRight3 = {
    Source.fromFile("H:\\紫花苜蓿数据库\\2022_12_19\\Cytoscape/CytoscapeInput-edges.txt".toFile).getLines().grouped(100000).foreach { x =>
      val lines = x.map { y =>
        if (y.startsWith("fromNode")) {
          ""
        } else {
          val l = y.split("\t").dropRight(3)
          l.head.split('.').init.mkString(".") + "\t" + l(1).split('.').init.mkString(".") + "\t" + l.drop(2).mkString("\t")
        }
      }.distinct.filter(_ != "")
      FileUtils.writeLines("H:\\紫花苜蓿数据库\\2022_12_19\\Cytoscape/CytoscapeInput.txt".toFile, lines.asJava, true)

    }
  }
}
